package com.leunpha.mini.utils;

import java.io.InputStream;
import java.net.URL;
/**
 * User: leunpha
 * Date: 14-5-11
 * Time: 下午8:59
 */
public class ClassUtils {
    public static ClassLoader getClassLoader(){
        ClassLoader classLoader = ClassUtils.class.getClassLoader();
        if(classLoader == null){
            classLoader = Thread.currentThread().getContextClassLoader();
            if(classLoader == null){
                classLoader = ClassLoader.getSystemClassLoader();
            }
        }
        return classLoader;
    }

    public static URL getResource(){
        return getClassLoader().getResource("/");
    }

    public static URL getResource(String name){
        return getClassLoader().getResource(name);
    }

    public static InputStream getResourceAsStream(){
        return getClassLoader().getResourceAsStream("/");
    }

    public static InputStream getResourceAsStream(String name){
        return getClassLoader().getResourceAsStream(name);
    }
}
